import service from '@/utils/request'
import {ElMessage} from "element-plus/es";

export const useTableInfoApi = (id: number) => {
    return service.get('/gen/table/' + id)
}


export async function useTableFieldApi(tableName: string | number) {
    if (tableName == null) {
        ElMessage.error("表名不能为空！");
        return;
    }
    const res = await service({
        url: '/gen/table/field/',
        method: "GET",
        params: {
            table: tableName
        }
    })
    return res
}

export async function useGrnCodeAPI(tableName: string | number) {
    const res = await service({
        url: '/gen/table/create',
        method: "GET",
        params: {tableJson: "{table:{name:hr_salary_data,child:[{table:{name:hr_salary_data_details}}]}}"}
        // params: tableJson

    })
    return res
}

export async function useGeneratorAPI(tableName: string | number) {
    if (tableName == null) {
        ElMessage.error("表名不能为空！");
        return;
    }
    const res = await service({
        url: '/gen/table/genCode',
        method: "GET",
        params: {table: tableName}
        // params: {table: "{table:{name:hr_salary_data,child:({table:{name:hr_salary_data_details}})}}"}

    })
    return res
}

export async function usegetSalaryDataAggAPI(tableName: string | number) {

    const res = await service({
        url: '/salary/getSalaryDataAgg',
        method: "GET",
        // params: {   table: tableName    }
        params: {table: "{'table':{'name':'HR_SALARY_DATA','child':[{'table':{'name':'HR_SALARY_DATA_DETAILS'}}]}}"}
    })
    return res
}

export async function useupdSalaryDataAggAPI(tableName: string | number) {

    const res = await service({
        url: '/salary/updSalaryData',
        method: "POST",
        // params: {   table: tableName    }
        params: {table: "{'table':{'name':'HR_SALARY_DATA','child':[{'table':{'name':'HR_SALARY_DATA_DETAILS'}}]}}"}
    })
    return res
}

export async function usedelSalaryDataAPI(tableName: string | number) {

    const res = await service({
        url: '/salary/delSalaryDataAgg',
        method: "POST",
        // params: {   table: tableName    }
        params: {table: "{classpatch:com.xisoft.devise.entity.salary.SalaryDataEntity,id:1111,2222}"}
    })
    return res
}
